package games.car;

import java.awt.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Config {
    static Properties properties = null;
    static FileInputStream fileInputStream = null;
    static String propertiesName = "conf/car/setting.properties";
//    static String propertiesName = "conf/car/setting-lager.properties";

    static {
        try {
            properties = new Properties();
            fileInputStream = new FileInputStream(propertiesName);
            properties.load(fileInputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void close(){
        try {
            if(fileInputStream != null){
                fileInputStream.close();
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }

    static void setProperties(String key,String value,String comments){
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(propertiesName);
            properties.setProperty(key,value);
            properties.store(fileOutputStream, comments);
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //全局变量
    public static boolean soundOn = false;//音效开关
    public static State state = State.READY;
    public enum State {
        READY,RUNNING,OVER,PAUSE
    }

    //游戏参数常量
    public static final int WINDOW_WIDTH = Integer.valueOf(properties.getProperty("WINDOW_WIDTH"));//窗口宽度
    public static final int WINDOW_HEIGHT = Integer.valueOf(properties.getProperty("WINDOW_HEIGHT"));//窗口高度
    public static final Color WINDOW_BACKGROUND_COLOR = Color.darkGray; //窗口背景色
    public static final int FRAME_WIDTH = 5; //窗口内边距
    public static final int CAR_DEFAULT_SPEED = Integer.valueOf(properties.getProperty("CAR_DEFAULT_SPEED")); //汽车默认移动速度
    public static final int FPS = 60; // 界面刷新频率
    public static final int CAR_WIDTH = Integer.valueOf(properties.getProperty("CAR_WIDTH")); //汽车宽度
    public static final int CAR_HEIGHT = Integer.valueOf(properties.getProperty("CAR_HEIGHT")); //汽车高度
    public static final String[] LEVEL_SPEED = properties.getProperty("LEVEL_SPEED").split(","); //汽车刷新间隔（毫秒）
    public static final int ROAD_LINE_WIDTH = Integer.valueOf(properties.getProperty("ROAD_LINE_WIDTH")); //路面线宽度
    public static final int ROAD_LINE_HEIGHT = Integer.valueOf(properties.getProperty("ROAD_LINE_HEIGHT")); //路面线长度
    public static final int PROP_DEFAULT_SPEED = Integer.valueOf(properties.getProperty("PROP_DEFAULT_SPEED")); //道具默认移动速度
    public static final int PROP_COIN_SCORE = Integer.valueOf(properties.getProperty("PROP_COIN_SCORE")); //道具金币积分
    public static final String PROP_VOICE = properties.getProperty("PROP_VOICE"); //道具音效
    public static final String BOOM_VOICE = properties.getProperty("BOOM_VOICE"); //碰撞爆炸音效
    public static final String BACKGROUND_VOICE = properties.getProperty("BACKGROUND_VOICE");//背景音乐
    public static final int MAX_SCORE = Integer.valueOf(properties.getProperty("MAX_SCORE"));//最大积分记录
    public static final String VERSION = properties.getProperty("VERSION");
    public static final int PROP_COVER_PER = Integer.valueOf(properties.getProperty("PROP_COVER_PER"));//保护罩刷出概率（百分占比）
    public static final int PROP_FIRE_PER = Integer.valueOf(properties.getProperty("PROP_FIRE_PER"));//攻击道具刷出概率（百分占比）
    public static final int PROP_SPEED_PER = Integer.valueOf(properties.getProperty("PROP_SPEED_PER"));//加速道具刷出概率（百分占比）
    public static final int PROP_SPEED_TIME = Integer.valueOf(properties.getProperty("PROP_SPEED_TIME"));//加速道具持续时间（秒）
}
